package com.woniu.carrent.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.woniu.carrent.mapper.TCityMapper;
import com.woniu.carrent.mapper.TLocationMapper;
import com.woniu.carrent.mapper.TProvinceMapper;

import com.woniu.carrent.pojo.TCity;
import com.woniu.carrent.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/position")
@CrossOrigin
@SaCheckLogin
public class PositionController {
    @Autowired
    private TProvinceMapper tProvinceMapper;
    @Autowired
    private TCityMapper tCityMapper;
    @Autowired
    private TLocationMapper tLocationMapper;
    /**
     * 获取所有省份
     * @return
     */
    @RequestMapping("/getAllProvince")
    public ResultMessage getAllProvince() {
        return ResultMessage.success(tProvinceMapper.selectList(null));
    }
    /**
     * 获取所有城市
     * @return
     */
    @RequestMapping("/getAllCity")
    public ResultMessage getAllCity() {
        return ResultMessage.success(tCityMapper.selectList(null));
    }
    /**
     * 获取所有位置
     * @return
     */
    @RequestMapping("/getAllLocation")
    public ResultMessage getAllLocation() {
        return ResultMessage.success(tLocationMapper.selectList(null));
    }
    /**
     * 根据省份id获取城市
     * @param pid
     */
    @GetMapping("/getCityByPid/{pid}")
    public ResultMessage getCityByPid(@PathVariable Integer pid) {
        return ResultMessage.success(tCityMapper.selectListById(pid));
    }

    /**
     * 根据城市id获取位置
     * @param cid
     */
    @GetMapping("/getLocationByCid/{cid}")
    public ResultMessage getLocationByCid(@PathVariable Integer cid) {
        return ResultMessage.success(tLocationMapper.selectListById(cid));
    }

}
